package com.example.wechat;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


public class discoverFragment extends Fragment {
    private  View root;
    private RecyclerView recyclerView;
    private Myadaptr mydata;
    private List<String> list_name,list_vale,img_name;
    private Context context;
    public discoverFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if(root==null){
            root= inflater.inflate(R.layout.discover_fragment, container, false);
        }
        initData();
        initRecyclerview();
        return root;
    }
    private void initData() {
        list_name = new ArrayList<>();
        list_vale=new ArrayList<>();
        img_name=new ArrayList<>();
        for (int i=0;i<10;i++){
            list_name.add("item"+i+"name");
            list_vale.add("item"+i+"vale");
            img_name.add("@tools:sample/avatars");
        }
    }
    private void initRecyclerview() {
        //获得Recyclerview
        recyclerView = (RecyclerView)root.findViewById(R.id.recyclerView3);
        //创建adapter类的对象
        mydata = new Myadaptr(getActivity(),list_name,list_vale,img_name);
        //网格布局
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),3);
        //将对象作为参数通过setAdapter方法设置给recylerview；
        recyclerView.setAdapter(mydata);
        //选择RecylerView的显示方式
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
}